package com.company.project.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.company.project.mapper.TeamUserMapper;
import com.company.project.common.exception.BusinessException;
import com.company.project.entity.TeamUserEntity;
import com.company.project.service.TeamUserService;
import com.company.project.vo.req.TeamUser;

@Service("teamUserService")
public class TeamUserServiceImpl extends ServiceImpl<TeamUserMapper, TeamUserEntity> implements TeamUserService {

	@Resource
	private TeamUserMapper teamUserMapper;
	
	@Override
	public void addTeamUser(TeamUserEntity entity) {
		TeamUserEntity teamUser = teamUserMapper.selectOne(Wrappers.<TeamUserEntity>lambdaQuery().eq(TeamUserEntity::getIdNumber, entity.getIdNumber()));
		if(teamUser!=null) {
			throw new BusinessException("用户"+entity.getName()+"已是团队成员！");
		}
		teamUserMapper.insert(entity);	
	}

	@Override
	public TeamUserEntity getTeamUserByDcicUserId(String dcicUserId) {
		TeamUserEntity teamUser = teamUserMapper.selectOne(Wrappers.<TeamUserEntity>lambdaQuery().eq(TeamUserEntity::getDcicUserId, dcicUserId));       
		return teamUser;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public IPage<TeamUser> getList(Page page, String area) {
		return teamUserMapper.getList(page, area);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public IPage<TeamUser> getListLastDay(Page page, List<String> teamIds, String area) {
		return teamUserMapper.getListLastDay(page, teamIds, area);
	}

}